package com.jeesite.modules.kj.utils;

import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.shiro.realms.K;
import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.kj.entity.KjSkill;
import com.jeesite.modules.kj.service.KjMemberIntegralHistoryService;
import com.jeesite.modules.kj.service.KjMemberIntegralsService;
import com.jeesite.modules.kj.service.KjMemberService;
import com.jeesite.modules.kj.service.KjSkillService;
import com.jeesite.modules.sys.entity.EmployeeOffice;
import com.jeesite.modules.sys.utils.EmpUtils;
import com.jeesite.modules.sys.utils.UserUtils;

import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class SkillUtil {

    public static final String CACHE_SKILL_ALL_LIST = "skillAllList";
    /**
     * 静态内部类，延迟加载，懒汉式，线程安全的单例模式
     */
    private static final class Static {
        private static KjSkillService kjSkillService = SpringUtils.getBean(KjSkillService.class);
    }
    public static String getSkills(String ids){
        List<KjSkill> skills = getKjSkills();
        List<String> skillStr = ListUtils.newArrayList();
        for (KjSkill ks: skills
             ) {
            if(ids.indexOf(ks.getId()) >= 0) {
                skillStr.add(ks.getName());
            }
        }
        return ListUtils.convertToString(skillStr, "、");
    }

    /**
     * 获取所有特长列表
     * @author ThinkGem
     */
    public static List<KjSkill> getKjSkills(){
        List<KjSkill> list = UserUtils.getCache(CACHE_SKILL_ALL_LIST);
        if (list == null){
            list = Static.kjSkillService.findList(new KjSkill());
            UserUtils.putCache(CACHE_SKILL_ALL_LIST, list);
        }
        return list;
    }
}
